/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package agen.util.graficos;

import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author juan
 */
public class XYChart {

    public static void agregarAPanel(JPanel panel, XYSeriesCollection data,
            String titulo, boolean unirPuntos, String titEjeX,String titEjeY){
        JFreeChart xyChart = ChartFactory.createXYLineChart(titulo,
                titEjeX,
                titEjeY,
                data,
                PlotOrientation.VERTICAL,
                true,
                true,
                false);
        XYPlot plot = (XYPlot) xyChart.getPlot();
        XYItemRenderer r = plot.getRenderer();
        if (r instanceof XYLineAndShapeRenderer) {
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
            renderer.setDrawSeriesLineAsPath(unirPuntos);
        }

        ChartPanel chartPanel  = new ChartPanel(xyChart);
        chartPanel.setFillZoomRectangle(true);
        chartPanel.setMouseWheelEnabled(true);
        
        panel.removeAll();
        
        javax.swing.GroupLayout panelLayOut = new javax.swing.GroupLayout(panel);
        panel.setLayout(panelLayOut);

        panelLayOut.setHorizontalGroup(
            panelLayOut.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLayOut.createSequentialGroup()
                .addContainerGap()
                .addComponent(chartPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelLayOut.setVerticalGroup(
            panelLayOut.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLayOut.createSequentialGroup()
                .addContainerGap()
                .addComponent(chartPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                .addContainerGap())
        );
        
        panel.validate();


    }
}
